package com.example.demo.sys.service.impl;

import com.example.demo.sys.dao.SysRole;
import com.example.demo.sys.mapper.SysRoleMapper;
import com.example.demo.sys.service.SysRoleService;
import com.example.demo.system.utility.PageInfo;
import com.example.demo.system.utility.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SysRoleServiceImpl implements SysRoleService {

    @Autowired
    private SysRoleMapper sysRoleMapper;

    //列表查询
    @Override
    public Result getList(Integer pageNum, Integer pageSize, String name) {
        Integer start = PageInfo.start(pageNum,pageSize);
        List<SysRole> list = sysRoleMapper.getList(start,pageSize,name);
        Integer listCount = sysRoleMapper.getListCount(name);
        PageInfo info = new PageInfo(pageNum, pageSize, listCount, list);
        return Result.success(info);
    }

    @Override
    public SysRole get(Integer id) {
        return sysRoleMapper.get(id);
    }

    @Override
    public Result add(SysRole sysRole) {
        sysRole.setModifeTime(new Date());
        sysRoleMapper.add(sysRole);
        return Result.success("新增成功");
    }

    @Override
    public Result update(SysRole sysRole) {
        sysRole.setModifeTime(new Date());
        sysRoleMapper.update(sysRole);
        return Result.success("修改成功");
    }

    @Override
    public Result delete(Integer id) {
        sysRoleMapper.delete(id);
        return Result.success("删除成功");
    }

}
